package sueldos;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

import com.swtdesigner.SWTResourceManager;

public class UatreReloaded extends Uatre{

	protected Shell shell;
	private Table tablaUatre;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			UatreReloaded window = new UatreReloaded();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(627, 463);
		shell.setText("SWT Application");
		shell.setLayout(new FormLayout());
		
		Composite composite = new Composite(shell, SWT.BORDER);
		FormData fd_composite = new FormData();
		fd_composite.top = new FormAttachment(0, 10);
		fd_composite.left = new FormAttachment(0, 5);
		fd_composite.right = new FormAttachment(100, -5);
		composite.setLayoutData(fd_composite);
		
		Label label = new Label(composite, SWT.NONE);
		label.setText("Empresa:");
		label.setFont(SWTResourceManager.getFont("Calibri", 11, SWT.BOLD));
		label.setBounds(0, 13, 57, 18);
		
		final Combo combo = new Combo(composite, SWT.READ_ONLY);
		combo.setVisibleItemCount(12);
		combo.setItems(new String[] {"SELECCIONAR EMPRESA.......", "ALEJANDRO CAMERON SA","AZTIRIA ELSA CLARA", "CLAVIER", "ESTANCIA EL ALBARDON S.A.", "ESTANCIA PAMPA GRANDE S.A.", "ISABEL DUGGAN DE DI CAMPELLO", "KENVIS S.A.", "LOS HUAICOS M.L. S.A.", "TRES ISLAS S.A."});
		combo.setFont(SWTResourceManager.getFont("Calibri", 11, SWT.BOLD));
		combo.setBounds(63, 10, 368, 26);
		combo.select(0);
		
		combo.setData("ALEJANDRO CAMERON SA","30-64795601-3"); 
		combo.setData("AZTIRIA ELSA CLARA","27-04712898-1"); 
		combo.setData("CLAVIER","30-55993155-8"); 
		combo.setData("ESTANCIA EL ALBARDON S.A.","30-52775240-6"); 
		combo.setData("ESTANCIA PAMPA GRANDE S.A.","30-55974576-2"); 
		combo.setData("ISABEL DUGGAN DE DI CAMPELLO","27-07587177-0"); 
		combo.setData("KENVIS S.A.","33-57006761-9"); 
		combo.setData("LOS HUAICOS M.L. S.A.","30-65757787-8"); 
		combo.setData("TRES ISLAS S.A.","30-52019247-2");
		
		Composite composite_2 = new Composite(shell, SWT.BORDER);
		fd_composite.bottom = new FormAttachment(composite_2, -6);
		composite_2.setLayout(new FormLayout());
		FormData fd_composite_2 = new FormData();
		fd_composite_2.left = new FormAttachment(composite, 0, SWT.LEFT);
		fd_composite_2.right = new FormAttachment(100, -5);
		fd_composite_2.top = new FormAttachment(0, 88);
		fd_composite_2.bottom = new FormAttachment(100, -69);
		composite_2.setLayoutData(fd_composite_2);
		
		tablaUatre = new Table(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
		tablaUatre.setFont(SWTResourceManager.getFont("Calibri", 10, SWT.NORMAL));
		FormData fd_tablaUatre = new FormData();
		fd_tablaUatre.bottom = new FormAttachment(100);
		fd_tablaUatre.right = new FormAttachment(100);
		fd_tablaUatre.top = new FormAttachment(0);
		fd_tablaUatre.left = new FormAttachment(0);
		tablaUatre.setLayoutData(fd_tablaUatre);
		tablaUatre.setHeaderVisible(true);
		tablaUatre.setLinesVisible(true);
		
		
		TableColumn tableColumn_2 = new TableColumn(tablaUatre, SWT.NONE);
		tableColumn_2.setWidth(100);
		tableColumn_2.setText("CUIL");
		
		TableColumn tableColumn_3 = new TableColumn(tablaUatre, SWT.NONE);
		tableColumn_3.setWidth(250);
		tableColumn_3.setText("Apellido y Nombre");

		TableColumn tableColumn = new TableColumn(tablaUatre, SWT.NONE);
		tableColumn.setWidth(100);
		tableColumn.setText("Cuota Sindical");


		
		Menu menu = new Menu(tablaUatre);
		tablaUatre.setMenu(menu);
		
		MenuItem eliminar = new MenuItem(menu, SWT.NONE);
		eliminar.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				try {
					TableItem item = tablaUatre.getSelection()[0];
					if (!item.getText(0).isEmpty()){
						borrarEmpleado(true, item.getText(0).toString());
						tablaUatre.removeAll();//tablaUatre.remove(tablaUatre.getSelectionIndices());
						empleadosPorEmpresa(combo.getData(combo.getItem(combo.getSelectionIndex())).toString(), tablaUatre);
						
					}
					
					
					
				} catch (Exception e2) {
					// TODO: handle exception
				}
			}
		});
		eliminar.setText("Dar de Baja");
		
		MenuItem mntmDarDeAlta = new MenuItem(menu, SWT.NONE);
		mntmDarDeAlta.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				try {
					TableItem item = tablaUatre.getSelection()[0];
					if (!item.getText(0).isEmpty()){
						borrarEmpleado(false, item.getText(0).toString());
						tablaUatre.removeAll();//tablaUatre.remove(tablaUatre.getSelectionIndices());
						empleadosPorEmpresa(combo.getData(combo.getItem(combo.getSelectionIndex())).toString(), tablaUatre);
					}
				} catch (Exception e2) {
					// TODO: handle exception
				}

			}
		});
		mntmDarDeAlta.setText("Dar de Alta");
		
		MenuItem mntmCuotaSindical = new MenuItem(menu, SWT.NONE);
		mntmCuotaSindical.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				try {
					TableItem item = tablaUatre.getSelection()[0];
					if (!item.getText(0).isEmpty()){
						cuotaSindical(true, item.getText(0).toString());
						tablaUatre.removeAll();//tablaUatre.remove(tablaUatre.getSelectionIndices());
						empleadosPorEmpresa(combo.getData(combo.getItem(combo.getSelectionIndex())).toString(), tablaUatre);
					}
				} catch (Exception e2) {
					// TODO: handle exception
				}

			}
		});
		mntmCuotaSindical.setText("Afiliado a UATRE");

		
		
		combo.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				if (combo.getSelectionIndex() > 0){
					tablaUatre.removeAll();
					
					empleadosPorEmpresa(combo.getData(combo.getItem(combo.getSelectionIndex())).toString(), tablaUatre);
					//String base = obtieneBase(combo.getData(combo.getItem(combo.getSelectionIndex())).toString());
					
				}
				//combo.getData(combo.getItem(combo.getSelectionIndex())).toString()
			
			}
		});

		
		
	}
}
